package com.simplehc7878.auth.common;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.http.HttpStatus;

import java.util.Collections;
import java.util.List;

@Schema(description = "返回对象（分页）")
@Data
public class PageResult<T> {

    @Schema(description = "状态码")
    private Integer code;
    @Schema(description = "返回信息")
    private String msg;
    @Schema(description = "返回数据")
    private List<T> data;
    @Schema(description = "总记录数")
    private long total;

    public static <T> PageResult<T> empty() {
        PageResult<T> pageResult = new PageResult<>();
        pageResult.setCode(HttpStatus.OK.value());
        pageResult.setMsg("success");
        pageResult.setData(Collections.emptyList());
        pageResult.setTotal(0);
        return pageResult;
    }

    public static <T> PageResult<T> success(long total, List<T> list) {
        PageResult<T> pageResult = new PageResult<>();
        pageResult.setCode(HttpStatus.OK.value());
        pageResult.setMsg("success");
        pageResult.setData(list);
        pageResult.setTotal(total);
        return pageResult;
    }
}
